import mysql.connector
import sys

conn = mysql.connector.connect(user='username', password='password', host='localhost', port='3306', database='dbName', use_unicode=True)
cursor = conn.cursor()
cursor.execute("select id,name from table1 where status = %s", ('1',)) #('1',)中逗号是必须的否者不是list
values = cursor.fetchall()
ids = []
names = []
size = 0
for value in values:
    ids.append(value[0])
    names.append(value[1])
    #print "id: %s, name: %s" %(value[0],value[1])
cursor.close()
conn.close()

#下面两行设置字符串中文编码
reload(sys)
sys.setdefaultencoding('utf-8')

with open('./eq_name_metric', 'w') as f:
    for i in range(len(ids)):
        for j in range(i+1,len(ids)):
            if names[i] == names[j]:
                f.write("id: {0}, name: {1}, id: {2}, name: {3}\n".format(ids[i],names[i],ids[j],names[j]))